<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="6">
        <div class="form-item">
          <span class="title">微信昵称</span>
          <el-input placeholder="请输入名称" v-model="param.membershipLevelCustomer.wechatNick"></el-input>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="form-item">
          <span class="title">充值时间</span>
          <el-date-picker
            v-model="createdateList"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :clearable="false"
          ></el-date-picker>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="form-item button-container">
          <el-button type="primary" @click="search" icon="el-icon-search">查询</el-button>
          <el-button type="primary" @click="resetSearchCotnet" icon="el-icon-refresh">重置</el-button>
        </div>
      </el-col>
    </el-row>

    <div class="table-body">
      <el-table :data="tableData" border v-loading="isLoading" style="width: 100%">
        <el-table-column prop="createTime" width="180" label="加入时间"></el-table-column>
        <el-table-column prop="purchaseTime" width="180" label="微信头像">
          <template slot-scope="scope">
            <template>
              <el-image class="header-image" fit="cover" :src="scope.row.headPic"></el-image>
              <div v-show="!scope.row.disabled"></div>
            </template>
          </template>
        </el-table-column>
        <el-table-column prop="wechatNick" label="微信昵称"></el-table-column>
        <el-table-column prop="money" label="当前余额">
          <template slot-scope="scope">
            ￥
            <span>{{scope.row.money}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="lastTime" label="最近一次充值时间"></el-table-column>
        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <el-button
              @click="handleTocz(scope.row)"
              v-if="isPermissionsBtn('member_cz')"
              size="small"
              type="success"
            >充值记录</el-button>
            <el-button
              @click="handleToxf(scope.row)"
              type="primary"
              size="small"
              v-if="isPermissionsBtn('member_xf')"
            >消费记录</el-button>
            <!-- <el-popconfirm title="确定销卡？" @onConfirm="handleClickDelete(scope.row)">
              <el-button
                style="margin-left:15px"
                size="small"
                type="danger"
                slot="reference"
                v-if="isPermissionsBtn('member_xk')"
              >销卡</el-button>
            </el-popconfirm> -->
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @current-change="currentPageChange"
          layout="prev, pager, next"
          :total="total"
        ></el-pagination>
      </div>
    </div>
    <el-dialog title="充值记录" :visible.sync="isVisible" width="50%">
      <MemberCzRecord @submit="getMag" :data="propdata" v-if="isVisible" />
    </el-dialog>
    <el-dialog title="储值卡详情" :visible.sync="isVisible1" width="50%">
      <MemberXfRecord @submit="changeInfo" :data="propdata1" v-if="isVisible1" />
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import MemberCzRecord from "./MemberCzRecord";
import MemberXfRecord from "./MemberXfRecord";
export default {
  name: "",
  data() {
    return {
      isVisible: false,
      isVisible1: false,
      isLoading: false,
      createdateList: [],
      param: {
        membershipLevelCustomer: {
          wechatNick: "",
          startTime: "",
          endTime: ""
        },
        queryRequest: {
          pageNum: 1,
          pageSize: 10
        }
      },
      tableData: [],
      total: 1,
      propdata:{},
      propdata1:{}
    };
  },
  components: {
    MemberCzRecord,
    MemberXfRecord
  },
  computed: {
    ...mapGetters(["isPermissionsBtn"])
  },
  beforeMount() {},
  mounted() {
    this.initData();
  },
  methods: {
    initData() {
      this.isLoading = true;
      if (this.createdateList.length > 0) {
        this.param.membershipLevelCustomer.startTime = this.createdateList[0];
        this.param.membershipLevelCustomer.endTime = this.createdateList[1];
      }
      this.$service.getMerberCustomerList(this.param).then(res => {
        this.isLoading = false;
        if (res.code == "00000") {
          if (
            res.data.records.length == 0 &&
            this.param.queryRequest.pageNum != 1
          ) {
            this.param.queryRequest.pageNum -= 1;
            this.initData();
          }
          this.tableData = res.data.records;
          this.total = res.data.total || 0;
        }
      });
    },
    search() {
      this.param.queryRequest.pageNum = 1;
      this.initData();
    },
    resetSearchCotnet() {
      //重置搜索条件
      this.param.membershipLevelCustomer.wechatNick = "";
      this.param.membershipLevelCustomer.startTime = "";
      this.param.membershipLevelCustomer.endTime = "";
      this.createdateList = [];
    },
    handleTocz(scope) {
      this.isVisible =true;
      this.propdata = JSON.parse(JSON.stringify(scope));
    },
    handleToxf(scope) {
      this.isVisible1 =true;
      this.propdata1 = JSON.parse(JSON.stringify(scope));
    },
    handleClickDelete(scope) {},
    currentPageChange(e) {
      this.param.queryRequest.pageNum = e;
      this.initData();
    },
    getMag() {
      this.isVisible = false;
      this.initData();
    },
    changeInfo() {
      this.isVisible1 = false;
      this.initData();
    }
  },
  watch: {}
};
</script>
<style scoped>
.header-image {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  font-size: 14px;
}
</style>
